package org.example.testdemo.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.annotation.Resource;
import org.example.testdemo.mapper.UserMapper;
import org.example.testdemo.pojo.PageReq;
import org.example.testdemo.pojo.User;
import org.example.testdemo.pojo.combination.UserInformation;
import org.example.testdemo.service.UserService;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public User findinUsername(String username) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("userName",username);
        return userMapper.selectOne(wrapper);
    }

    @Override
    public IPage<UserInformation> getUser(String name, String department, PageReq pageReq) {
        Page<UserInformation> page = new Page<>(pageReq.getCurrent(), pageReq.getSize());
        return userMapper.getUser(name,department,page);
    }

    @Override
    public User findByUserIdAndBCode(String userId, String bCode) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("userId",userId);
        wrapper.eq("b_Code",bCode);
        return userMapper.selectOne(wrapper);
    }

    @Override
    public User findByName(String name) {
        return null;
    }

    @Override
    public IPage<UserInformation> getUserExclude(String name, String department, String projectId, PageReq pageReq) {
        Page<UserInformation> page = new Page<>(pageReq.getCurrent(), pageReq.getSize());
        return userMapper.getUserExclude(name,department,projectId,page);
    }
}
